%% Author: Hua Hu, Date: 2012-08-22
%% For Cs144002U card only

function [ret] = SetupUSB(handle)
global ExperimentParameters

[ret, sysinfo] = CsMl_GetSystemInfo(handle);
CsMl_ErrorHandler(ret, 1, handle);

%% Acquisition parameters
set_falling_time = ExperimentParameters.dropDurations(ExperimentParameters.dropDurationIndex);
acq.SampleRate =  ExperimentParameters.samplingFrequencies; % sample rate 100 MHz
acq.ExtClock = 0;           % set to 1 if use external clock 100 MHz
acq.Mode = 1026;            % mode = 2 or 1026 (enable ref. clock + dual mode)
acq.Depth = acq.SampleRate*set_falling_time/1000;
acq.SegmentSize = acq.SampleRate*set_falling_time/1000;
acq.TriggerTimeout = 15e6;

[ret] = CsMl_ConfigureAcquisition(handle, acq);
CsMl_ErrorHandler(ret, 1, handle);

%% Channel parameters
ExperimentParameters.GageParameters.Channel.Channel = 1;        
ExperimentParameters.GageParameters.Channel.Coupling = 1;       % AC=2; DC=1
ExperimentParameters.GageParameters.Channel.DiffInput = 0;      % fixed
ExperimentParameters.GageParameters.Channel.InputRange = 2200;  % fixed
ExperimentParameters.GageParameters.Channel.Impedance = 50;     % fixed

[ret] = CsMl_ConfigureChannel(handle, ExperimentParameters.GageParameters.Channel);
CsMl_ErrorHandler(ret, 1, handle);

%% Trigger  parameters
trig.Trigger = 1;       % default
trig.Slope = 1;
trig.Level = 40;
trig.Source = -1;       % if Source = -1 (External), then slope = 1, level = 40;
                        % default Source = 1. but if Source = 0 (Disable?)
trig.ExtCoupling = 1;   % DC Coupling, fixed
trig.ExtRange = 2000;   % fixed

[ret] = CsMl_ConfigureTrigger(handle, trig);
CsMl_ErrorHandler(ret, 1, handle);

ret = 1;
end